package org.afun.oldhand.forum.fragment;

import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import org.afun.oldhand.R;
import org.afun.oldhand.base.BaseFragment;
import org.afun.oldhand.forum.adapter.ForumBottomItemAdapter;
import org.afun.oldhand.forum.adapter.ForumTopItemAdapter;
import org.afun.oldhand.forum.javaBean.BottomBase;
import org.afun.oldhand.forum.javaBean.BottomType1;
import org.afun.oldhand.forum.javaBean.BottomType2;
import org.afun.oldhand.forum.javaBean.BottomType3;
import org.afun.oldhand.forum.javaBean.ItemBottomContentBean;
import org.afun.oldhand.forum.javaBean.ItemTopBean;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link Forum0Fragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class Forum0Fragment extends BaseFragment {
    private List<ItemTopBean> data = new ArrayList<>();
    private List<BottomBase> data2 = new ArrayList<>();
    private View view;

    public Forum0Fragment() {
        // Required empty public constructor
    }

    public static Forum0Fragment newInstance(String param1, String param2) {
        Forum0Fragment fragment = new Forum0Fragment();
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return initView();
    }

    @Override
    public View initView() {
        if(view==null){
            view=View.inflate(mContext,R.layout.fragment_forum0,null);
        }

        // =====全部论坛区=====
        RecyclerView recyclerView=view.findViewById(R.id.recyclerViewForum1);
        data.add(new ItemTopBean("全部论坛"));
        data.add(new ItemTopBean("其他论坛"));
        data.add(new ItemTopBean("其他论坛"));
        data.add(new ItemTopBean("其他论坛"));
        data.add(new ItemTopBean("其他论坛"));
        data.add(new ItemTopBean("其他论坛"));
        data.add(new ItemTopBean("其他论坛"));
        // 设置线性布局
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this.mContext,
                LinearLayoutManager.HORIZONTAL,false);
        recyclerView.setLayoutManager(linearLayoutManager);

        ForumTopItemAdapter forumTopItemAdapter=new ForumTopItemAdapter(data,this.mContext);
        recyclerView.setAdapter(forumTopItemAdapter);

        forumTopItemAdapter.setOrderItemClickListener(new ForumTopItemAdapter.OnForumTopItemRecyclerItemClickListener() {
            @Override
            public void onItemRecyclerItemClick(int position) {
                Log.e("testForum","onRecyclerItemClick1:"+position);
            }
        });

        // =====bottom=====
        RecyclerView recyclerView2=view.findViewById(R.id.recyclerViewForum2);
        BottomBase p0=new BottomType1("精选分类",R.drawable.forum_loadimg,R.drawable.forum_loadimg,
                new ArrayList<>(Arrays.asList("媳妇当车模","论坛热帖","论坛红人馆","论坛直播")));
        data2.add(p0);
        data2.add(new BottomBase());
        data2.add(new BottomBase());
        BottomBase p1=new BottomType3(R.drawable.forumimg,"实现基础的滑动之后",
                R.drawable.defaulthead,"afuna","175此浏览");
        data2.add(p1);
        data2.add(new BottomBase());
        data2.add(new BottomBase());
        data2.add(new BottomBase());
//        data2.add(new ItemBottomContentBean(null,"实现基础的滑动之后",null,"aFun","2.9万次浏览"));
//        data2.add(new ItemBottomContentBean(null,"实现基础的滑动之后的再滑动再滑动",null,"aFun","2.9万次浏览"));
//        data2.add(new ItemBottomContentBean(null,"实现基础的滑动之后",null,"aFun","2.9万次浏览"));
//        data2.add(new ItemBottomContentBean(null,"实现基础的滑动之后",null,"aFun","2.9万次浏览"));
//        data2.add(new ItemBottomContentBean(null,"实现基础的滑动之后",null,"aFun","2.9万次浏览"));
        // 设置线性布局

//        // 网格布局
//        GridLayoutManager gridLayoutManager=new GridLayoutManager(this.mContext,2);
//        recyclerView2.setLayoutManager(gridLayoutManager);

        // 瀑布流
        StaggeredGridLayoutManager staggeredGridLayoutManager=new StaggeredGridLayoutManager(2,LinearLayoutManager.VERTICAL);
        recyclerView2.setLayoutManager(staggeredGridLayoutManager);

        ForumBottomItemAdapter forumBottomItemAdapter=new ForumBottomItemAdapter(data2,this.mContext);
        recyclerView2.setAdapter(forumBottomItemAdapter);


        forumBottomItemAdapter.setOrderItemClickListener(new ForumBottomItemAdapter.OnForumBottomItemRecyclerItemClickListener() {
            @Override
            public void onItemRecyclerItemClick(int position) {
                Log.e("testForum2","onRecyclerItemClick2:"+position);
            }
        });

        return view;
    }
}